<?php
// 永不超时 -- cli 不能用 nginx apache
set_time_limit(0);
include __DIR__.'/function.php';
require __DIR__.'/vendor/autoload.php';
use QL\QueryList;

// 连接数据库
$db = new PDO("mysql:host=127.0.0.1;dbname=zfw","root","root");

// update
$sql_update = "update zfw_articles set body= ? where id = ?";
$stmt = $db->prepare($sql_update);

// 内容页面
$sql = "select id,url from zfw_articles where body = ''";
// 查询
// PDO::FETCH_ASSOC 关联数组形式
$rows = $db->query($sql)->fetchAll(PDO::FETCH_ASSOC);

foreach($rows as $item){
    extract($item);
    $html = http_request($url);
    // 分析采集到的内容
    $ret = QueryList::Query($html,[
        "body" => ['.bd','html']
    ])->data;
    // 内容
    $body = $ret[0]['body'];
    // 入库
    $stmt->execute([$body,$id]);
}